import { login } from '@/api/login'

const user = {
  state: {
    userInfo:null
  },

  mutations: {
    SET_STORAGE: (state, value) => {
      state.userInfo = value;
      localStorage.setItem('user',JSON.stringify(value));
    },
    REMOVE_STORAGE: (state) => {
      state.userInfo = null;
      localStorage.removeItem('user');
    },
    
  },

  actions: {
    // 登录
    Login({ commit }, data) {
      return new Promise((resolve, reject) => {
        login(data).then(response => {
          const data = response.entity;
					commit('SET_STORAGE', data)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },
    
    loginOut({ commit }){
    	commit('REMOVE_STORAGE')
    	
    }
    
    


  }
}

export default user
